import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner scan=new Scanner(System.in);
        String t=scan.nextLine();
        String s=scan.nextLine();
        System.out.println(match(s,t));
    }
    public static boolean match(String s,String t){
        boolean[][]dp=new boolean[s.length()+1][t.length()+1];
        dp[0][0]=true;
        for(int i=0;i<=s.length();i++){
            for(int j=1;j<=t.length();j++){
                if(t.charAt(j-1)=='*'){
                    if(i==0){
                        dp[i][j]=dp[i][j-1];
                    }else{
                        if(s.charAt(i-1)=='.'||s.charAt(i-1)>='0'&&s.charAt(i-1)<='9'
                                ||s.charAt(i-1)>='a'&&s.charAt(i-1)<='z'
                                ||s.charAt(i-1)>='A'&&s.charAt(i-1)<='Z'){
                            dp[i][j]=dp[i-1][j]||dp[i][j-1];
                        }
                    }
                }else{
                    if(i>0&&defs(t.charAt(j-1),s.charAt(i-1))){
                        dp[i][j]=dp[i-1][j-1];
                    }
                }
            }
        }
        return dp[s.length()][t.length()];
    }
    public static boolean defs(char t,char s){
        if(t=='?'){
            return true;
        }
        if(t>='a'&&t<='z'){
            t=(char)(t-'a'+'A');
        }
        if(s>='a'&&s<='z'){
            s=(char)(s-'a'+'A');
        }
        return s==t;
    }
}